package edu.hebeu.evil.freshmenguide.View;

import android.content.Context;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;

import com.github.ksoichiro.android.observablescrollview.ObservableScrollView;

/********************************************
 * 工程名：FreshmenGuide
 * 包名：edu.hebeu.evil.freshmenguide.View
 * 时间：16-7-5 下午12:40
 * 作者：白雨濃 evil
 * 邮箱：evilbai@foxmail.com
 * 内容：将WebView嵌套进ScrollView
 ********************************************/
public class ScrollViewNextWebView extends ObservableScrollView
{
    private GestureDetector mGestureDetector;
    protected View.OnTouchListener mGestureListener;

    public ScrollViewNextWebView(Context context, AttributeSet attrs)
    {
        super(context, attrs);
        mGestureDetector = new GestureDetector(context, new YScrollDetector());
        setFadingEdgeLength(0);
    }

    @Override
    public boolean onInterceptHoverEvent(MotionEvent event)
    {
        return super.onInterceptTouchEvent(event) && mGestureDetector.onTouchEvent(event);
    }

    // Return false if we're scrolling in the x direction
    private class YScrollDetector extends GestureDetector.SimpleOnGestureListener
    {
        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
        {
            if (Math.abs(distanceY) > Math.abs(distanceX))
            {
                return true;
            }
            return false;
        }
    }
}
